//
//  WBFristPageTabbarToolView.swift
//  weibo
//
//  Created by  郭航 on 16/6/29.
//  Copyright © 2016年 郭航. All rights reserved.
//

import UIKit

class WBFristPageTabbarToolView: UIView {
    
    var dataModel: WBFristPageDataModel? {
        didSet {
            repostsButton?.setTitle(dataModel?.repostStr, forState: .Normal)
            commentsButton?.setTitle(dataModel?.commentStr, forState: .Normal)
            attitudesButton?.setTitle(dataModel?.attitudeStr, forState: .Normal)
        }
    }

    /// 转发数
    var repostsButton: UIButton?
    
    /// 评论数
    var commentsButton: UIButton?
    
    /// 表态数
    var attitudesButton: UIButton?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = UIColor.whiteColor()
        
        repostsButton = addButton("timeline_icon_retweet")
        commentsButton = addButton("timeline_icon_comment")
        attitudesButton = addButton("timeline_icon_unlike")
        
        repostsButton?.snp_makeConstraints(closure: { (make) in
            make.leading.top.bottom.equalTo(self)
            make.width.equalTo(commentsButton!)
        })
        
        commentsButton?.snp_makeConstraints(closure: { (make) in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(repostsButton!.snp_trailing)
            make.width.equalTo(attitudesButton!)
        })
        
        attitudesButton?.snp_makeConstraints(closure: { (make) in
            make.top.bottom.trailing.equalTo(self)
            make.leading.equalTo(commentsButton!.snp_trailing)
        })
        
        addLine().snp_makeConstraints(closure: { (make) in
            make.centerY.equalTo(self)
            make.centerX.equalTo(repostsButton!.snp_trailing)
        })
        
        addLine().snp_makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.centerX.equalTo(attitudesButton!.snp_leading)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func addButton(imageName: String) -> UIButton {
        let button = UIButton()
        
        button.setImage(UIImage(named: imageName), forState: .Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: .Highlighted)
        
        addSubview(button)
        
        return button
    }
    
    private func addLine() -> UIImageView {
        let line = UIImageView(imageName: "timeline_card_bottom_line")
        
        addSubview(line)
        
        return line
    }
    
}
